package com.newenergy.wisehome.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.newenergy.wisehome.R;
import com.newenergy.wisehome.common.util.ImageUtil;
import com.newenergy.wisehome.data.bean.BallLight;

import java.util.List;

/**
 * 分享选择房间适配器
 * Created by jnl on 2017/9/14.
 */

public class SelectGroupAdapter extends RecyclerArrayAdapter<BallLight> {
    private Context mContext;

    public void refreshData(List<BallLight> datas) {
        clear();
        if (datas != null && datas.size() > 0) addAll(datas);
        notifyDataSetChanged();
    }

    public SelectGroupAdapter(Context context) {
        super(context);
        mContext=context.getApplicationContext();
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int
            viewType) {
        return new ViewHolder(parent);
    }

    private class ViewHolder extends BaseViewHolder<BallLight> {

        private TextView tvName;
        private ImageView ivStatus;
        private ImageView ivIcon;


        public ViewHolder(ViewGroup parent) {
            super(parent, R.layout.list_group);
            tvName = $(R.id.tv_name);
            ivStatus = $(R.id.iv_status);
            ivIcon=$(R.id.iv_icon);
        }

        @Override
        public void setData(BallLight data) {
            super.setData(data);
            tvName.setText(data.getName());
            ivStatus.setVisibility(data.isChecked() ? View.VISIBLE : View.GONE);

            int imageId = ImageUtil.getImageId(data.getIcName());

            Glide.with(mContext).load(imageId).diskCacheStrategy(DiskCacheStrategy.NONE).into(ivIcon);
        }
    }
}
